package com.company.cloud.captcha.modules.controller;

import com.company.cloud.captcha.modules.api.model.CaptchaVO;
import com.company.cloud.captcha.modules.model.common.ResponseModel;
import com.company.cloud.captcha.modules.service.CaptchaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Log4j2
@RestController
@RequestMapping("/app/user/captcha")
@Api(tags="User_App_图形验证码")
public class CaptchaController {

    @Autowired
    private CaptchaService captchaService;

    @Value("${aj.captcha.type}")
    private String captchaType;

    @PostMapping("/getCaptcha")
    @ApiOperation(value="获取图形验证码", response= CaptchaVO.class)
    public ResponseModel get() {
        CaptchaVO captchaVO = new CaptchaVO();
        captchaVO.setCaptchaType(captchaType);
        return ResponseModel.successData(captchaService.get(captchaVO));
    }

    @PostMapping("/checkCaptcha")
    @ApiOperation(value="检验验证码", response=CaptchaVO.class)
    public ResponseModel check(@RequestBody CaptchaVO captchaVO) {
        captchaVO.setCaptchaType(captchaType);
        return ResponseModel.successData(captchaService.check(captchaVO));
    }

//    @PostMapping("/verify")
//    public ResponseModel verify(@RequestBody CaptchaVO captchaVO) {
//        return captchaService.verification(captchaVO);
//    }

}
